﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace baseClass.controls
{
    public partial class employee_private : UserControl
    {
        private Color saveNormalFC = Color.White;
        public employee_private()
        {
            InitializeComponent();
            saveNormalFC = dobEd.ForeColor;
            bankAccNoEd.isToUpperCase = true;
        }
        public virtual void LoadData()
        {
            nationalityCb.LoadData();
            ethnicCb.LoadData();
            religionCb.LoadData();
            maritalStatCb.LoadData();
            bloodTypeCb.LoadData();
            eduDegreeCb.LoadData();
            comUnionStatCb.LoadData();
            comPartyStatCb.LoadData();
        }
        public virtual void SetData(data.baseDS.employeeRow row)
        {
            dobEd.myDateTime = row.dob;
            pobEd.Text = row.pob;
            placeOfOriginEd.Text = (row.IsplaceOfOriginNull() ? "" : row.placeOfOrigin);

            nationalityCb.myValue = (row.Isnationality1Null() ? null : row.nationality1);
            ethnicCb.myValue = (row.IsethnicNull() ? null : row.ethnic);
            religionCb.myValue = (row.IsreligionNull() ? null : row.religion);
            maritalStatCb.myValue = (row.IsmaritalStatusNull() ? application.myTypes.maritalStatus.None : (application.myTypes.maritalStatus)row.maritalStatus);

            eduDegreeCb.myValue = (row.IseduLevelNull() ? null : row.eduLevel);
            eduAreaEd.Text = (row.IseduAreaNull() ? null: row.eduArea);

            bankAccNoEd.Text = (row.IsbankAccNoNull() ? null : row.bankAccNo);
            bankNameEd.Text = (row.IsbankNameNull() ? null : row.bankName);
            bankBranchEd.Text = (row.IsbankBranchNull() ? null : row.bankBranch);
            
            bloodTypeCb.myValue = (row.IsbloodGroupNull() ? application.myTypes.bloodType.None : (application.myTypes.bloodType)row.bloodGroup);

            if (row.IscomPartyJoinDateNull())
            {
                comPartyChk.Checked = false;
                comPartyDateEd.myDateTime = common.Consts.constNullDate;
            }
            else
            {
                comPartyChk.Checked = true;
                comPartyDateEd.myDateTime = row.comPartyJoinDate;
            }
            comPartyStatCb.myValue = (row.IscomPartyStatusNull() ? null : row.comPartyStatus);

            if (row.IscomUnionJoinDateNull())
            {
                comUnionChk.Checked = false;
                comUnionDateEd.myDateTime = common.Consts.constNullDate;
            }
            else
            {
                comUnionChk.Checked = true;
                comUnionDateEd.myDateTime = row.comUnionJoinDate;
            }
            comUnionStatCb.myValue = (row.IscomUnionStatusNull() ? null : row.comUnionStatus);
        }
        public virtual void GetData(data.baseDS.employeeRow row)
        {
            row.dob = dobEd.myDateTime;
            row.pob = pobEd.Text.Trim();
            if (placeOfOriginEd.Text.Trim() == "") row.SetplaceOfOriginNull(); else row.placeOfOrigin = placeOfOriginEd.Text.Trim();
            
            if (nationalityCb.myValue.Trim() == "") row.Setnationality1Null(); else row.nationality1 = nationalityCb.myValue.Trim();
            if (ethnicCb.myValue.Trim() == "") row.SetethnicNull(); else row.ethnic = nationalityCb.myValue.Trim();
            if (religionCb.myValue.Trim() == "") row.SetreligionNull(); else row.religion = religionCb.myValue.Trim();
            row.maritalStatus = (byte)maritalStatCb.myValue;
            
            if (eduDegreeCb.myValue.Trim() == "") row.SeteduLevelNull(); else row.eduLevel = eduDegreeCb.myValue.Trim();
            if (eduAreaEd.Text.Trim() == "") row.SeteduAreaNull(); else row.eduLevel = eduAreaEd.Text.Trim();
            
            if (bankAccNoEd.Text.Trim() == "") row.SetbankAccNoNull(); else row.bankAccNo = bankAccNoEd.Text.Trim();
            if (bankNameEd.Text.Trim() == "") row.SetbankNameNull(); else row.bankName = bankNameEd.Text.Trim();
            if (bankBranchEd.Text.Trim() == "") row.SetbankBranchNull(); else row.bankBranch = bankBranchEd.Text.Trim();

            row.bloodGroup = (byte)bloodTypeCb.myValue;

            if (comPartyChk.Checked)  row.comPartyJoinDate = comPartyDateEd.myDateTime;
            else row.SetcomPartyJoinDateNull();
            if (comPartyStatCb.myValue.Trim() == "") row.SetcomPartyStatusNull(); else row.comPartyStatus = comPartyStatCb.myValue.Trim();

            if (comUnionChk.Checked) row.comUnionJoinDate = comUnionDateEd.myDateTime;
            else row.SetcomUnionJoinDateNull();
            if (comUnionStatCb.myValue.Trim() == "") row.SetcomUnionStatusNull(); else row.comUnionStatus = comUnionStatCb.myValue.Trim();
        }

        public virtual bool CheckData()
        {
            bool retVal = true;
            dobLbl.ForeColor = saveNormalFC;
            pobLbl.ForeColor = saveNormalFC;
            if (dobEd.myDateTime == common.Consts.constNullDate)
            {
                dobLbl.ForeColor = application.Settings.sysColorHiLightFG;
                retVal = false;
            }
            if (pobEd.Text.Trim() == "")
            {
                pobLbl.ForeColor = application.Settings.sysColorHiLightFG;
                retVal = false;
            }

            comPartyDateLbl.ForeColor = saveNormalFC;
            comUnionDateLbl.ForeColor = saveNormalFC;
            if (comPartyChk.Checked)
            {
                if (comPartyDateEd.myDateTime == common.Consts.constNullDate)
                {
                    comPartyDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }
            if (comUnionChk.Checked)
            {
                if (comUnionDateEd.myDateTime == common.Consts.constNullDate)
                {
                    comUnionDateLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }

            bankNameLbl.ForeColor = saveNormalFC;
            bankBranchLbl.ForeColor = saveNormalFC;
            if (bankAccNoEd.Text.Trim()!="")
            {
                if (bankNameEd.Text.Trim() == "")
                {
                    bankNameLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
                if (bankBranchEd.Text.Trim() == "")
                {
                    bankBranchLbl.ForeColor = application.Settings.sysColorHiLightFG;
                    retVal = false;
                }
            }
            return retVal;
        }
        public virtual void LockEdit(bool state)
        {
            dobEd.ReadOnly = state;
            pobEd.ReadOnly = state;
            placeOfOriginEd.ReadOnly = state;

            nationalityCb.Enabled = !state;
            ethnicCb.Enabled = !state;
            religionCb.Enabled = !state;
            maritalStatCb.Enabled = !state;

            eduDegreeCb.Enabled = !state;
            eduAreaEd.ReadOnly = state;

            bankAccNoEd.ReadOnly = state;
            bankNameEd.ReadOnly = state;
            bankBranchEd.ReadOnly = state;

            bloodTypeCb.Enabled = !state;

            comPartyGb.Enabled = !state;
            comUnionGb.Enabled = !state;
        }
        public virtual void SetFocus()
        {
            this.Focus();
            dobEd.Focus();
        }
    }
}
